extern crate hammer;
use std::os;
-use std::io::{UserExecute, fs};
use cargo::ops;
use cargo::{execute_main_without_stdin};
target: None,
};
- try!(ops::compile(&root, compile_opts).map(|_| None::<()>).map_err(|err| {
+ let test_executables = try!(ops::compile(&root, compile_opts).map_err(|err| {
CliError::from_boxed(err, 101)
}));
let test_dir = root.dir_path().join("target").join("test");
- let mut walk = try!(fs::walk_dir(&test_dir).map_err(|e| {
- CliError::from_error(e, 1)
- }));
-
- for file in walk {
- // TODO: The proper fix is to have target knows its expected
- // output and only run expected executables.
- if file.display().to_string().as_slice().contains("dSYM") { continue; }
- if !is_executable(&file) { continue; }
-
- try!(util::process(file).exec().map_err(|e| {
+ for file in test_executables.iter() {
+ try!(util::process(test_dir.join(file.as_slice())).exec().map_err(|e| {
CliError::from_boxed(e.box_error(), 1)
}));
}
Ok(None)
}
-
-fn is_executable(path: &Path) -> bool {
- if !path.is_file() { return false; }
- path.stat().map(|stat| stat.perm.intersects(UserExecute)).unwrap_or(false)
-}
pub target: Option<&'a str>,
}
-pub fn compile(manifest_path: &Path, options: CompileOptions) -> CargoResult<()> {
+pub fn compile(manifest_path: &Path, options: CompileOptions) -> CargoResult<Vec<String>> {
let CompileOptions { update, env, shell, jobs, target } = options;
let target = target.map(|s| s.to_string());
try!(ops::compile_targets(env.as_slice(), targets.as_slice(), &package,
&PackageSet::new(packages.as_slice()), &resolve, &mut config));
- Ok(())
+ let test_executables: Vec<String> = targets.iter()
+ .filter_map(|target| {
+ if target.get_profile().is_test() {
+ debug!("Run Target: {}", target.get_name());
+ Some(target.get_name().to_string())
+ } else {
+ debug!("Skip Target: {}", target.get_name());
+ None
+ }
+ }).collect();
+
+ Ok(test_executables)
}
fn source_ids_from_config() -> CargoResult<Vec<SourceId>> {
assert!(out == format!("{}\n\n{}\n\n\n{}\n\n", head, internal, external).as_slice() ||
out == format!("{}\n\n{}\n\n\n{}\n\n", head, external, internal).as_slice());
})
+
+test!(dont_run_examples {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [project]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+ "#)
+ .file("src/lib.rs", r#"
+ "#)
+ .file("examples/dont-run-me-i-will-fail.rs", r#"
+ fn main() { fail!("Examples should not be run by 'cargo test'"); }
+ "#);
+ assert_that(p.cargo_process("cargo-test"),
+ execs().with_status(0));
+})